import Vue from "vue";
import VueRouter from "vue-router";
import Index from "../views/Index.vue";
import ArticleType from "../views/ArticleType.vue";
import Articles from "../views/Articles.vue";
import Article from "../views/Article.vue";
import Login from "../views/Login.vue";
import Register from "../views/Register.vue";
import UserInfo from "../views/UserInfo.vue";
import Mails from "../views/Mails.vue";
import Mail from "../views/Mail.vue";
import Collection from "../views/Collection.vue";
import Admin from "../views/admin/Admin.vue";
import WriterArticle from "../views/admin/WriterArticle";
import AdminArticles from "../views/admin/AdminArticles";
import AdminUsers from "../views/admin/AdminUsers";

Vue.use(VueRouter);

const routes = [
  {
    path: "/collection",
    name: "Collection",
    component: Collection,
  },
  {
    path: "/mailGetter/:id",
    name: "Mail",
    component: Mail,
  },
  {
    path: "/mail",
    name: "Mails",
    component: Mails,
  },
  {
    path: "/userinfo/:username",
    name: "UserInfo",
    component: UserInfo,
  },
  {
    path: "/register",
    name: "Register",
    component: Register,
  },
  {
    path: "/login",
    name: "Login",
    component: Login,
  },
  {
    path: "/article/:id",
    name: "Article",
    component: Article,
  },
  {
    path: "/articles",
    name: "Articles",
    component: Articles,
  },
  {
    path: "/ArticleType",
    name: "ArticleType",
    component: ArticleType,
  },
  {
    path: "/",
    name: "Index",
    component: Index,
  },
  {
    path: "/admin",
    component: Admin,
    children: [
      {
        // 当 /admin 匹配成功再进行匹配，
        path: "article",
        component: WriterArticle,
      },
      {
        // 当 /admin 匹配成功再进行匹配，
        path: "articles",
        component: AdminArticles,
      },
      {
        // 当 /admin 匹配成功再进行匹配，
        path: "users",
        component: AdminUsers,
      },
    ],
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

export default router;
